
cc.Class({
    extends: cc.Component,

    properties: {
        launcher:require('SkillLauncher')
    }, 
    onLoad(){
        this.stop=true
        this.positionx=null;
        this.positiony=null;

        this.launcher.setSkillParentNode(global.GameLoop.GameMgr.no_BulletSelfLayer)
        global.Event.on('OTHERPLANE',this.fire.bind(this), this);
        global.Event.on('PLANEPOSITION',this.planePosition.bind(this), this);
        global.Event.on('PLAYERDIE',this.stopFire.bind(this),this);

        this.otherPlayerTime=5;
    },

    onDestroy(){
        global.Event.off('OTHERPLANE')
        global.Event.off('PLANEPOSITION')
        global.Event.off('PLAYERDIE')
    },
    planePosition(data){
        this.positionx=data.x;
        this.positiony=data.y;
    },
    fire(){
        this.startFire();
    },
    setOptions(option,gameUI){
        
        this.otherPlayerTime=5;
        this.logicOptions=option
        this.s_gameUI = gameUI;
    },
    startFire(){ //装载子弹
        this.launcher.reset();
        var skills = this.logicOptions.status[0];
        this.launcher.addLauncher(skills)
    },

    stopFire(){
        cc.log('stopFire')
        if(!this.stop){
            return
        }
        this.stop = false;

        this.scheduleOnce(()=>{
            this.launcher.reset();
            this.node.runAction(cc.sequence(cc.delayTime(0.5),cc.moveBy(1,cc.v2(0,-1500)),cc.callFunc(()=>{
                global.GameLoop.GameMgr.otherPlayerOut();
                // this.node.destroy()
            })))
        },0.5)
    },

    onGetProp(no){
        return false
    },



    



    update(dt){
        if(cc.isPauseGame){
            return
        }
        
        this.otherPlayerTime-=dt;
        
        global.GameLoop.GameMgr.s_gameUI.showLiaoji(-this.otherPlayerTime/(5))
        if(this.otherPlayerTime<=0){
            this.stopFire();
            return
        }

        if(this.positionx>=0){
            if(this.node.x-this.positionx<-150){
                this.node.x+=8;
            }
            if(this.node.x-this.positionx>-150 && this.node.x>-300){
                this.node.x-=8;
            }
        }else{
            if(this.node.x-this.positionx>150){
                this.node.x-=8;
            }
            if(this.node.x-this.positionx<150 && this.node.x<300){
                this.node.x+=8;
            }
        }
        
        if(this.node.y-this.positiony<-100){
            this.node.y+=8;
        }
        if(this.node.y-this.positiony>-100 && this.node.y>-660){
            this.node.y-=8;
        }
            
        
    }
    
});
